package com.liao.seckill.rabbitmq;

import com.alibaba.fastjson.JSON;
import com.liao.seckill.pojo.TbOrderInf;
import com.liao.seckill.service.GoodsMiaoshaService;
import com.liao.seckill.service.GoodsService;
import com.liao.seckill.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class MiaoShaReceive {

    private final OrderService orderService;

    public MiaoShaReceive(OrderService orderService) {
        this.orderService = orderService;
    }

    @RabbitListener(queues = RabbitMQConfig.QUEUE_NAME)
    public void receiver(String msg) {
        MiaoShaMessage miaoShaMessage = JSON.parseObject(msg, MiaoShaMessage.class);
        orderService.secKillMQ(miaoShaMessage.getGoodsId(), miaoShaMessage.getUserId());
    }
}
